<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%
	String hospitalNotesJson= (String)request.getAttribute("hospitalNotesJson");
	String pageJson= (String)request.getAttribute("pageJson");
 %>


<!--内容部分-->

    
<div class="list_NR">
    <!-- 归档弹框 -->
    <div id="overlay" class="overlay"></div>
	<div id="win" class="win">
	<h2 ><span id="close" onclick="closeOverlay()" >×</span></h2>
	    <input type="hidden" name="first_level_guid" value="">
		<table>
			<tr><td class="input_td">姓　　名:</td><td><input name='patient_name' disabled class="input_text" type="text" title=''></td></tr>
			<tr><td class="input_td">身份证号:</td><td><input name='id_number' disabled class="input_text" type="text" title=''></td></tr>
			<tr><td class="input_td">识 别 码:</td><td><input  name='mr_id' disabled class="input_text" type="text" title=''></td></tr>
			<tr><td class="input_td">出院科室:</td><td><input name='office_name' disabled class="input_text" type="text" title=''></td></tr>
			<tr><td class="input_td">出院日期:</td><td><input name='out_hospital_date' disabled class="input_text" type="text" title=''></td></tr>
			<tr><td class="input_td changeCss">归档日期:</td><td><input class="input_text" name="traceDateTime" value="" type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate: '%y-%M-%d'})"></tr>
			<tr><td class="input_td changeCss">特殊标记:</td><td><input  class="input_text" name="specialIndication" style="height:20px;width:30px;margin-bottom:5px;"value="2" type="checkbox"></tr>
			<tr><td></td><td><a class="input_submit" onclick="Complete_Pigeonhole()">归档审核</a></td></tr>
		</table>
	</div>
    <div class="loc">
        <h3>未归病案查询</h3>
       <!--  <ul class="loc_loc">
          	  病案归档 > 未归病案
        </ul> -->
    </div>
    
      <div class="list_con_table">
        <input type="hidden" value="${medRecordQuery.totalCounts }" id="totalCountsHidden">
		<form action="${basePath}/medrecord/unPigeonhole" method="get" id="queryForm">
		<input type="hidden" name="currentPage" value="${medRecordQuery.currentPage }" id="currentPageHidden">
    	<input type="hidden" name="pageSize" value="${medRecordQuery.pageSize }" id="pageSizeHidden">
    	<div class="search_table">
           <ul class="clearfix" style="margin-bottom:0;">

            <li class="Label_1" style="width:11%">出院日期：&nbsp;</li>
               <li class="Label_2" style="width:27%;">
                   <input style="width:42%;" class="input_box" name="outHospitalStartDate" value='<fmt:formatDate value="${medRecordQuery.outHospitalStartDate}" pattern="yyyy-MM-dd"/>' onFocus="WdatePicker()" type="text" > 
                   - <input style="width:42%" class="input_box" name="outHospitalEndDate"  value='<fmt:formatDate value="${medRecordQuery.outHospitalEndDate}" pattern="yyyy-MM-dd"/>' onFocus="WdatePicker()" type="text" >
               </li>
               <li class="Label_1" style="width:11%">识别码：&nbsp;</li>
               <li class="Label_2">
               	<input class="input_box" type="text" id="scanBarCode"   name="mrId" value='${medRecordQuery.mrId }' />
               </li>
               <li class="Label_1" style="width:11%">住院次数：&nbsp;</li>
               <li class="Label_2">
               	<input class="input_box" id="visitNumber" type="text"  name="visitNumber" value='${medRecordQuery.visitNumber}' />
               </li>
               <li class="Label_1" style="width:11%">身份证号：&nbsp;</li>
               <li class="Label_2" style="width:27%"><input class="input_box" type="text" style="width:94%;"  name="idCard" id='' value='${medRecordQuery.idCard}' />
               </li>
               <li class="Label_1" style="width:11%">出院科室：&nbsp;</li>
               <li class="Label_2" style="text-align:left;padding-left:5px" >
               
               	<select class="input_box"  name="outHospitalOfficeId">
               		<option value="">请选择</option>
               		<c:forEach var="office" items="${offices }"> 
               			<option <c:if test="${medRecordQuery.outHospitalOfficeId==office.id}">selected="selected"</c:if> value="${office.id }">${office.name }</option>
               		</c:forEach>
                	
                	</select>
                </li>
                
                 <li class="Label_1"  style="width:11%">患者名：&nbsp;</li>
               <li class="Label_2">
               	<input class="input_box" type="text"  name="name" value='${medRecordQuery.name }' />
               </li>
                
                <li class="Label_1" style="width:11%;height:76px;line-height:76px;">离院方式：&nbsp;</li>
                <li class="Label_2" style="width:88%;height:76px;text-align:left;padding-top:10px;">
                	<c:forEach items="${basicInfo['outHospitalTypes']}" var="outHospitalType">
                		<input type="checkbox" class="check_cl" name="outHospitalTypeIds" value="${outHospitalType.id}" checked="checked"><span>${outHospitalType.name}</span>
                		
                	</c:forEach>
                	<input class="btn_qx" type="button" name="" onclick="selectAll()" value="全选">
                	<input class="btn_qx" type="button" name="" onclick="disableAll()" value="取消">
                
                </li>
                <li class="Label_5">
                    <div class="right">
                    	<a id="Add" onclick="queryFormSubmit()">查询</a>
                    	
                    	<a id="Add" target="_blank" href="http://localhost:28088/medical-export/export305/queryExportMedicalVisitForm">数据拉取</a>
                    </div>
                </li>
            </ul>
        </div>
     </form>

   </div>

   <table class="Search_tableList"cellpadding="0" cellspacing="0">

       <tr>
           <td class="tdLabel_4">姓名</td>
           <td class="tdLabel_4">身份证号</td>
           <td class="tdLabel_4">识别码</td>
           <td class="tdLabel_4">住院次数</td>
           <td class="tdLabel_4">出院日期</td>
           <td class="tdLabel_4">出院科室</td>
           <td class="tdLabel_4">离院方式</td>
           <td class="tdLabel_4">状态</td>
           <td class="tdLabel_4">操作</td>
       </tr>
       <tbody id="tbody">
       	<%-- <c:forEach var="med" items="${bindList }">
       		<tr>
       			<td class='tdLabel_5'>
       				<div class='imgIcon'><img src='${basePath}/static/publics/images/file.png' alt=''/></div>
       			</td>
       			<td class='tdLabel_5'><fmt:formatDate value="${med.uploadDate}" pattern="yyyy-MM-dd"/></td>
       			<td class='tdLabel_5'>${med.name}</td>
       			<td class='tdLabel_5'>${med.id_number}</td>
       			<td class='tdLabel_5'>${med.treatment_no}</td>
       			<td class='tdLabel_5'><fmt:formatDate value="${med.treatment_date}" pattern="yyyy-MM-dd"/></td>
       			<td class='tdLabel_5'>${med.treatment_type_name}</td>
       			<td class='tdLabel_5'>${med.hospital_name }</td>
       			<td class='tdLabel_5'>${med.comment }</td>
       			<td class='tdLabel_5'>
       				<c:if test="${empty med.first_level_medical_guid }">
       					<a target='_blank' href='${basePath}/bind/pigeonHoleList?id=${med.id}'>绑定</a>
       				</c:if>
       				<c:if test="${not empty med.first_level_medical_guid }">
       					已绑定
       				</c:if>
       			</td>
       		</tr>
       	</c:forEach> --%>
        </tbody>
           
       
    </table>

    <div id="pageList" class="pageList" hidden="true">
        <ul class="pagination clearfix" id="page_plus"></ul>
        <div class="pagination">
            <div>总共：<b id="totalPage">0</b> 条信息    当前页是第 <b id="currentPage">0/0</b>　页</div>
        </div>
    </div>
    
</div>
<style>
	.changeCss{color: red;}
	.changeinputCss{border: 1px red solid;}
	.overlay{z-index:100;position:absolute;top:-138px;left:0px;background-color:#000;opacity:0.5;filter:alpha(opacity=50);display:none;}
	.win{z-index:10000;position:absolute;top:130px;left:60%;width:400px;height:450px;background:#fff;margin:-102px 0 0 -202px;display:none;}
	h2{text-align:right;padding-right: 5px;margin-top: -3px;margin-bottom:10px;}
	h2 span{color:#000000;font-size:25;color:#000000;cursor:pointer;}
	.input_text{
		height: 38px;
		width: 240px;
		margin-bottom: 10px;
		padding-left:2px;
	}
	.input_td{
		padding-left: 38px;
		padding-right:4px;
		text-align:right;
	}
	.input_submit{
	    display:block;
		height: 38px;
		width: 240px;
		line-height:38px;
		background-color: #07a396;
		color: white;
		font-size: 18;
		font-family: 幼圆;
		border:none;
		text-align: center;
	}
</style>

<!--script JS部分-->
<script type="text/javascript" src="${basePath}/static/publics/assets/jquery/jquery.min.js"></script>
<script type="text/javascript" src="${basePath}/static/publics/assets/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="${basePath}/static/publics/assets/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${basePath}/static/publics/assets/jqPaginator/jqPaginator.js"></script>
<script type="text/javascript">
	function queryFormSubmit(){
		$("#currentPageHidden").val("1");
		$("#queryForm").submit();
	}
	
	
	$("#scanBarCode").change(function(){
		var $this=$(this);
		var inentity=$this.val();
		if(inentity!=null && inentity!='' && inentity!=undefined){
			if(isContainMark(inentity)){
				var mrId=inentity.split("-")[0];
				var visitNumber=inentity.split("-")[1];
				
				if(!isNumber(visitNumber)){
					alert("请重新扫描条形码");
					$("#scanBarCode").val("").focus();
					$("#visitNumber").val("");
					
					return;
				}
				//alert(mrId+"--"+visitNumber);
				$("#scanBarCode").val("").val(mrId);
				$("#visitNumber").val("").val(visitNumber);
				$("#queryForm").submit();
			}
		}
	});
	
	function isNumber(value) {
	    var patrn = /^[0-9]*$/;
	    if (patrn.exec(value) == null || value == "") {
	        return false
	    } else {
	        return true
	    }
	}
	
	
	function isContainMark(inentity){
		var reg = RegExp(/-/);
		return reg.test(inentity);
	}

	$(function(){
		
		$("#scanBarCode").focus();
		
		var data= <%=hospitalNotesJson%>;
		var page= <%=pageJson%>;
		var html ="";
		var basePath = $("#basePath").val();
		for(var i in data){
			var med=data[i];
			//将json转成字符串存在归档按钮上
			var medString=JSON.stringify(med);
			html+="<tr data-guid='"+med.first_level_guid+"'>"+
		                "<td class='tdLabel_5'>"+(med.patient_name==undefined?'':med.patient_name)+"</td>"+
		                "<td class='tdLabel_5'>"+(med.id_number==undefined?'':med.id_number)+"</td>"+
		               " <td class=tdLabel_5>"+(med.mr_id==undefined?'':med.mr_id)+"</td>"+
		               " <td class=tdLabel_5>"+(med.visit_number==undefined?'':med.visit_number)+"</td>"+
		               " <td class=tdLabel_5>"+(med.out_hospital_date==undefined?'':med.out_hospital_date)+"</td>"+
		                "<td class='tdLabel_5'>"+(med.office_name==undefined?'':med.office_name)+"</td>"+
		               " <td class='tdLabel_5'>"+(med.out_hospital_type_name==undefined?'':med.out_hospital_type_name)+"</td>"+
		               " <td class='tdLabel_5'>未归档</td>"+
		               " <td class='tdLabel_5'><a class='int' onclick='scan(this)'>查看患者数据</a>&nbsp;<a class='int' data-info='"+medString+"' onclick='Pigeonhole(this)'>归档</a></td>"
		       		   //" <td class='tdLabel_5'><a class='int' href='"+basePath+"/medrecord/completePigeonholeForm?guid="+med.first_level_guid+"'>归档</a></td>"
		}
		$("#tbody").html(html);
		if(data.length > 0){
			$("#pageList").show();
			initPage(page);
			var htmlHeight=$('.list_NR').height();
			var htmlWidth=$('.list_NR').width();
			var left = $('html').css('left');
			var top = $('html').css('top');
			$(".overlay").css({
				height:htmlHeight,
				width:htmlWidth,
				left:left,
				top:top
			});
		}else{
			$("#pageList").attr("hidden",true);
		}
		
	});
	
	function initPage(page){
		 var totalCounts = page.totalCounts;
		 var pageSize = page.pageSize;
		 var visiblePages = 5;
		 var currentPage = page.currentPage;
		 var totalPages = page.totalPages;
		 $('#page_plus').jqPaginator({

		        totalCounts: totalCounts,
		        pageSize:pageSize,
		        visiblePages: visiblePages,
		        currentPage: currentPage,

		        first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
		        prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
		        next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
		        last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
		        page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
		        onPageChange: function (num,type) {

		     		if(type !='init'){
		     			$("#currentPageHidden").val(num);
						$("#pageSizeHidden").val(pageSize);
						$("#queryForm").submit();
					}else{
						 $("#totalPage").html(totalCounts);
			            $("#currentPage").html(num+"/"+totalPages);
			            $("#currentPageHidden").val(currentPage);
					    $("#pageSizeHidden").val(pageSize);
					}
		           
		        }
		    });

	}
	//查看数据病案事件
    function scan(obj){
		 var target=$(obj);
		 var guid=target.closest("tr").attr("data-guid");
		// window.open('${corePath}/medical_record/searchHomePageIndexForm?visitGuid='+guid);
		 window.open('${corePath}/medical_record/searchHomePageIndexForm?visitGuid='+guid);
	 }
	
	//归档按钮事件
	function Pigeonhole(t){
		target=$(t);
		//拿到对应的json对象
		var Pigeonhole_info=JSON.parse($(t).attr("data-info"));
		//console.log(Pigeonhole_info)
		for(var k in Pigeonhole_info){
			$("input[name="+k+"]").val(Pigeonhole_info[k]);
		}
		//归档日期默认为当前日期
		var date = new Date();  
	    var seperator1 = "-";  
	    var seperator2 = ":";  
	    var month = date.getMonth() + 1;  
	    var strDate = date.getDate();  
	    if(month >= 1 && month <= 9) {  
	        month = "0" + month;  
	    }  
	    if(strDate >= 0 && strDate <= 9) {  
	        strDate = "0" + strDate;  
	            }  
	    var end = date.getFullYear() + seperator1 + month + seperator1 + strDate +" " + date.getHours() + seperator2 + date.getMinutes() +  
	          seperator2 + date.getSeconds();  
	    $("input[name='traceDateTime']").val(end); 
	    
	    $("#overlay").show();
		$("#win").show();
	}
	//关闭弹框
	function closeOverlay(){
		$("#win input").val("");
		$("#overlay").hide();
		$("#win").hide();
	}
	//弹框完成归档审核按钮
	function Complete_Pigeonhole(){
		var guid=$("input[name='first_level_guid']").val();
		//归档日期
		var traceDateTime=$("input[name='traceDateTime']").val();
		
		var specialIndication;
		specialIndication =  $("input[name='specialIndication']:checked").val()==undefined?1:$("input[name='specialIndication']:checked").val();
		//出院日期
		//var out_hospital_date=$("input[name='out_hospital_date']").val();
		//将出院日期和归档日期转成毫秒数进行大小判断
		//var traceDateTime_ms = (new Date(traceDateTime)).getTime();
		//var out_hospital_date_ms = (new Date(out_hospital_date)).getTime();
		//归档日期要大于等于出院日期
		/*if(traceDateTime_ms<out_hospital_date_ms){
			layer.alert("归档日期不能小于出院日期!",{icon:7});
			return;
		}*/
		if(traceDateTime==null||traceDateTime==""){
			layer.alert("归档日期不能为空!",{icon:7});
			return;
		}
		

		$.ajax({
			type:'post',
			url:"${basePath}/medrecord/ajaxCompletePigeonhole",
			data:{guid:guid,traceDateTime:traceDateTime,specialIndication:specialIndication},
			success:function(result){
				//console.log(result);
				if(result.success){
					$("#win input").val("");
					$("#overlay").hide();
					$("#win").hide();
					target.closest("td").prev("td").html("已归档");
					target.closest("td").html("").html("已归档");
					
					layer.alert('归档审核完成',{icon:1});
					//layer.alert(result.msg,{icon:1});
					
				}else{
					layer.alert(result.msg,{icon:7});
					return;
				}
			}
		})
	}
	
	
	
	function selectAll(){
		  $('input[name="outHospitalTypeIds"]').each(function(){  
	          //此处如果用attr，会出现第三次失效的情况  
	          $(this).prop("checked",true);  
	      });  
	}

	function disableAll(){
		  $('input[name="outHospitalTypeIds"]').each(function(){  
	          //此处如果用attr，会出现第三次失效的情况  
	          $(this).prop("checked",false);  
	      });  
	}
	
	
</script>
